package com.zofer.study.string;

/**
 * @description 字符串中统计字母和数字的数量
 * @date: 2020/10/15 10:53
 */
public class StatisticsLetterAndNumberNum {
    public static void main(String[] args) {
        String str = "534fgfd5456你kiu94好4";
        int letterNum = 0;
        int numberNum = 0;
        for (int i = 0; i < str.length() ; i++) {
            char ch = str.charAt(i);
            if (ch >= '0' && ch <= '9'){
                numberNum++;
            }else if ((ch >= 'a' && ch < 'z') || (ch >= 'A' && ch < 'Z')){
                letterNum++;
            }
        }
        System.out.println("数字个数:"+numberNum+" ,字母个数:"+letterNum);
    }
}

